package vision.nvhuong.service;

import java.util.concurrent.ConcurrentHashMap;

import vision.nvhuong.dao.impl.StudentDaoImpl;
import vision.nvhuong.enums.ServiceName;


/**
 * This class will cache services
 * 
 * @author nvhuong
 * 
 */
public class ServicesHolder {
	private static final ConcurrentHashMap<ServiceName, Object> cache = new ConcurrentHashMap<ServiceName, Object>();

	public static Object getService(ServiceName serviceName) {
		Object service = cache.get(serviceName);
		if (service == null) {
			switch (serviceName) {

			case STUDENT_SERVICE:
				service = new StudentService(
						new StudentDaoImpl());
				break;

			default: {
			}
			}
			cache.putIfAbsent(serviceName, service);
		}
		return cache.get(serviceName);

	}
}
